package com.CloudDream.Item;

import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.List;

public class Creator {
    private ItemStack itemStack;

    /*
     * Inventory
     */
    public Creator(Material material, String displayName, List<String> lore, String mark, int s, boolean light) {

        ItemStack itemStack = new ItemStack(material, 1, (byte) s);
        ItemMeta im = itemStack.getItemMeta();
        if (displayName != null && mark != null) {
            im.setDisplayName(displayName);
            itemStack.setItemMeta(im);
        }
        if (lore != null && mark != null) {
            List<String> list = new ArrayList<>();
            for (String l : lore) {
                list.add(l);
            }
            im.setLocalizedName(mark);
            im.setLore(list);
        }
        if (light) {
            im.addEnchant(Enchantment.LUCK, 1, true);
            im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
            im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
        }
        itemStack.setItemMeta(im);
        this.itemStack = itemStack;
    }

    /*
     * GUI
     */
    public Creator(Material material, String displayName, List<String> lore, int s, boolean light) {
        ItemStack itemStack = new ItemStack(material, 1, (byte) s);
        ItemMeta im = itemStack.getItemMeta();
        if (im != null) {
            if (displayName != null) {
                im.setDisplayName(displayName);
                itemStack.setItemMeta(im);
            }
            if (lore != null) {
                im.setLore(lore);
            }
            if (light) {
                im.addEnchant(Enchantment.LUCK, 1, true);
                im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
                im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
            }
        }
        itemStack.setItemMeta(im);
        this.itemStack = itemStack;
    }

    public ItemStack get() {
        return itemStack;
    }
}

